package com.example.demo.admin.gecco.crawler.mzt;

import com.example.demo.admin.gecco.entity.CategoryType;
import com.geccocrawler.gecco.pipeline.Pipeline;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.scheduler.SchedulerContext;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SaveCategoryPipeline implements Pipeline<IndexPage> {

    private static String role = "piclist";

    @Override
    public void process(IndexPage bean) {
        List<CategoryType> categoryTypes = bean.getCategoryTypes();
        for (CategoryType categoryType : categoryTypes) {

            if(categoryType.getUrl()!=null && categoryType.getUrl().indexOf(role)>=0){
                HttpRequest sub = bean.getRequest().subRequest(categoryType.getUrl());
                sub.addParameter("tag", ""+categoryType.getId());
                System.out.format("url: {%s}",sub.getUrl());
                //SchedulerContext.into(sub);
            }
        }
    }
}